#!/bin/bash

# 复制panel文件夹到xfce4配置文件夹
cp -r /home/feibot/platform/resources/panel /home/feibot/.config/xfce4/
cp -r /home/feibot/platform/resources/*.{svg,jpg,png,bmp} /home/feibot/resources 2>/dev/null
# XFCE4 面板配置文件路径
XML_FILE="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml"
NEW_XML_FILE="/home/feibot/cmds/xfce4-panel.xml"
BACKUP_FILE="$XML_FILE.bak"

# 备份原始 panel 配置文件（仅当备份文件不存在时）
if [ ! -f "$BACKUP_FILE" ]; then
    cp "$XML_FILE" "$BACKUP_FILE" || { echo "备份失败: $XML_FILE"; exit 1; }
    echo "已备份原始文件为: $BACKUP_FILE"
fi

# 替换 XML 文件
cp "$NEW_XML_FILE" "$XML_FILE" || { echo "替换失败: $NEW_XML_FILE"; exit 1; }

# 确保正确的 DISPLAY 变量（适用于远程或 GUI 运行）
export DISPLAY=:0

# 彻底重启 XFCE4 面板
xfce4-panel --quit
#sleep 2  # 等待面板完全退出
pkill xfconfd
#删除缓存，避免仍采用缓存的配置启动面板
rm -rf ~/.cache/sessions/*
# 重新启动面板
nohup xfce4-panel > /dev/null 2>&1 &
echo "已成功将 AnyDesk 添加到xfce4-panel面板"
